<?php
// 清理缓存
$modules     = array('Index', 'Mobile', 'Admin');
$directories = array();
foreach ($modules as $v) {
    $directories[] = "./{$v}/Runtime/~runtime.php";
    $directories[] = "./{$v}/Runtime/~rest_runtime.php";
    $directories[] = "./{$v}/Runtime/~app.php";
    $directories[] = "./{$v}/Runtime/Cache";
    $directories[] = "./{$v}/Runtime/Data";
    $directories[] = "./{$v}/Runtime/Logs";
    $directories[] = "./{$v}/Runtime/Temp";
}

foreach ($directories as $path) {
	removeDirectory($path);
	echo "<div style='border:2px solid green; background:#f1f1f1; padding:20px;margin:20px;width:800px;font-weight:bold;color:green;text-align:center;'>\"" . $path . "\" have been cleaned clear! </div>";
}

/**
 * 删除目录及其文件
 * 
 * @param string $dirname
 * @return boolean
 */
function removeDirectory($dirname)
{
    if (!file_exists($dirname)) {
        return FALSE;
    }
    
    if (is_file($dirname) || is_link($dirname)) {
        return unlink($dirname);
    }

    $dir = dir($dirname);
    while (FALSE !== ($entry = $dir->read())) {
        if ($entry == '.' || $entry == '..') {
            continue;
        }

        removeDirectory($dirname . DIRECTORY_SEPARATOR . $entry);
    }

    $dir->close();
    
    return rmdir($dirname);
}